<?php
/**
 * Created by PhpStorm.
 * User: kkw
 * Date: 2019/1/31
 * Time: 18:44
 */
namespace kkw\user\response;
use kkw\user\table\UserTable;
use kkw\user\Util;
use suda\core\Request;
use suda\core\Response;

class UpdateUserResponse extends  Response
{
    public function onRequest(Request $request)
    {
        Util::printHeader();
        $json = Request::json();
        $id= $json['id'];
        $name= $json['name'];
        $password = $json['password'];
        $mobile = $json['mobile'];
        $user = new UserTable();
        try {
            $user->update(['name'=>$name,'password'=>$password,'mobile'=>$mobile],['id'=>$id]);
        } catch (\suda\exception\SQLException $e) {
            $this->json(['code'=>$e->getCode(),'message'=> '更新数据成功']);
        }
        $this->json(['code'=>0,'message'=>'更新数据成功']);
    }
}